package com.red.springmanual.springmybatis.use;


import com.red.springmanual.springmybatis.frame.RedScan;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;

@ComponentScan("com.red.springmanual.springmybatis")
@RedScan("com.red.springmanual.springmybatis.use.mapper")
public class AppConfig {

    @Bean
    public SqlSessionFactory sqlSessionFactory() throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        SqlSessionFactory sq = new SqlSessionFactoryBuilder().build(resourceAsStream);
        return sq;
    }
}
